<template>
  <section>
    <el-card class="box-card">
      <div></div>
      <el-button icon="el-icon-document-add"  type="primary" size="small" @click="preserve()">
        保存修改
      </el-button>
      <el-button icon="el-icon-arrow-left"  type="primary" size="small" @click="back()">
        返回
      </el-button>
    </el-card>
    <el-card class="box-card">
      <el-form
        label-width="130px"
        style="margin-left: -50px;"
      >
        <el-form-item label="文 件 标 题">
          <el-input class="el-title" placeholder="请输入文件标题" v-model="fileDto.name"></el-input>
        </el-form-item>
        <el-form-item label="文 件 内 容">
          <el-input class="el-title" type="textarea" v-model="fileDto.fileContent" :rows="24"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
  </section>
</template>

<script>

  import { mapGetters } from "vuex";
  export default {
    name: "templateEditor",
    data(){
      return{
        fileDto:{
          name:"",
          fileContent:""
        },
        ueditorConfig:{
          initialFrameHeight: 500,
        }
      }
    },
    created(){
      this.getReadFileList()
      console.log("打印参数",this.$route.query.fileName)
    },
    mounted(){},
    computed: {
      ...mapGetters({
        TempReadFile: "TempReadFile",
      })
    },
    methods:{
      //保存修改
      preserve(){
        var params = {
          fileContent: this.fileDto.fileContent,
          fileName:this.$route.query.fileName,
          oldFileName:this.$route.query.fileName
        }
        console.log("打印参数",params)
        this.$store.dispatch("writeFileContentUsingPOSTS",{fileWriteDto:params}).then(ret => {
          this.$message({
            message:"修改成功！",
            type:"success"
          })
        }).catch(() => {
          this.$message({
            message:"修改失败，请重新修改！",
            type:"error"
          })
        })
      },
      getReadFileList(){
        var param = {
          fileName:this.$route.query.fileName
        }
        this.$store.dispatch("readFileContentUsingGETS",param).then(ret => {
          this.fileDto.name = ret.data.name;
          this.fileDto.fileContent = ret.data.fileContent
        })
      },
      //返回
      back() {
        this.$router.go(-1)
      }
    },
    components: {
    }
  }
</script>

<style scoped>
  .el-ueditor{
    width: 90%;
    margin-left: 90px;
  }
  .el-cont{
    float: left;
    font-size: 14px;
  }
  .el-title{
    width: 94%;
    margin-left: 10px;
  }
</style>
